package org.jsola.hr.web;

import org.jsola.approval.dto.IssuedApproFlowAddDTO;
import org.jsola.approval.vo.ApproFlowVO;
import org.jsola.core.Result;
import org.jsola.hr.constant.HrConstants;
import org.jsola.hr.provider.IApproProviderService;
import org.jsola.user.core.TokenUser;
import org.jsola.user.core.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 审批
 */
@RestController("hrApprovalController")
@RequestMapping(HrConstants.API_PATH + "/v1/approval")
public class ApprovalController implements IApprovalControllerAPI {

    @Autowired
    IApproProviderService approProviderService;


    @Override
    @PostMapping("/publishFlow")
    public Result publishApproFlow(@RequestBody @NotNull String flowInfo) {
        TokenUser tokenUser = UserContext.getUser();
        // todo 查看项目权限校验

        return Result.success(approProviderService.publishFlow(flowInfo, tokenUser));
    }

    @Override
    @PostMapping(value = "/saveIssuedApproFlow")
    public Result<List<ApproFlowVO>> saveIssuedApproFlow(@Valid @RequestBody IssuedApproFlowAddDTO issuedApproFlowAddDTO) {
        TokenUser tokenUser = UserContext.getUser();
        // todo 新增审批流程表权限校验

        return Result.success(
                approProviderService.saveIssuedApproFlow(issuedApproFlowAddDTO, tokenUser)
        );
    }
}
